package org.gd.hellojaxb;

import org.gd.hellojaxb.example.map.MapAdaptersFactory;

import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

@XmlRootElement(name = "xml_map")
@XmlAccessorType(XmlAccessType.FIELD)
public class SimpleXmlMap implements Map<String, String> {

    @XmlElement(name = "map")
    @XmlJavaTypeAdapter(MapAdaptersFactory.StringStringMapAdapter.class)
    private Map<String, String> map;

    public SimpleXmlMap() {
        map = new TreeMap<String, String>();
    }

    public SimpleXmlMap(Map<? extends String, ? extends String> m) {
        this();
        putAll(m);
    }

    @Override
    public int size() {
        return map.size();
    }

    @Override
    public boolean isEmpty() {
        return map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return map.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return map.containsKey(value);
    }

    @Override
    public String get(Object key) {
        return map.get(key);
    }

    @Override
    public String put(String key, String value) {
        return map.put(key, value);
    }

    @Override
    public String remove(Object key) {
        return map.remove(key);
    }

    @Override
    public void putAll(Map<? extends String, ? extends String> m) {
        map.putAll(m);
    }

    @Override
    public void clear() {
        map.clear();
    }

    @Override
    public Set<String> keySet() {
        return map.keySet();
    }

    @Override
    public Collection<String> values() {
        return map.values();
    }

    @Override
    public Set<Entry<String, String>> entrySet() {
        return map.entrySet();
    }
}
